package com.global.college.ui.presenter;

import android.content.Context;
import android.util.Log;

import com.global.college.api.BaseResponseModel;
import com.global.college.api.ProgressSubscriber;
import com.global.college.base.BasePresenter;
import com.global.college.ui.interfaces.IRegistView;

/**
 * 注册
 */
public class RegistPresenter extends BasePresenter {

    private IRegistView mIRegistView;

    public RegistPresenter(Context context) {
        super(context);
    }

    public void setRegistView(IRegistView registView){
        mIRegistView = registView;
    }

    /**
     * 注册
     * @param
     */
    public void getRegist(String phone,String code,String password,String inviteCode){
        mAuthRequestClient.regist( phone, code, password,inviteCode).subscribe(new ProgressSubscriber<BaseResponseModel>(mContext,true) {
            @Override
            public void onNext(BaseResponseModel registModel) {
                if(null != mIRegistView){
                    mIRegistView.onRegistSuccess(registModel);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIRegistView){
                    mIRegistView.onRegistFail(e.getMessage());
                }
            }
        });
    }

    /**
     * 获取验证码
     * @param
     */
    public void getSmsCode(String phone){
        Log.i("获取验证码---手机号",phone);
        mAuthRequestClient.getSmsCode(phone).subscribe(new ProgressSubscriber<Object>(mContext,true) {
            @Override
            public void onNext(Object smsModel) {
                if(null != mIRegistView){
                    mIRegistView.onGetSmsCodeSuccess(smsModel);
                }
            }
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIRegistView){
                    mIRegistView.onGetSmsCodeFail(e.getMessage());
                }
            }
        });
    }

}
